﻿using System;
using NUnit.Framework;

namespace CodeContrib.Tests
{
	public class RandomDateTimeTests
	{
		[Test, TestCaseSource(typeof (DateTimeSources), "Days")]
		public void Next_With_Day_Range(int days)
		{
			// Arrange
			var min = new DateTime(1970, 1, 1);
			var max = min.AddDays(days);

			var randomDateTime = new RandomDateTime(min, max);

			// Act
			var random = randomDateTime.Next();

			// Assert
			Assert.GreaterOrEqual(random, min);
			Assert.LessOrEqual(random, max);
		}

		[Test, TestCaseSource(typeof (DateTimeSources), "Hours")]
		public void Next_With_Hour_Range(int hours)
		{
			// Arrange
			var min = new DateTime(1970, 1, 1);
			var max = min.AddHours(hours);

			var randomDateTime = new RandomDateTime(min, max);

			// Act
			var random = randomDateTime.Next();

			// Assert
			Assert.GreaterOrEqual(random, min);
			Assert.LessOrEqual(random, max);
		}

		[Test, TestCaseSource(typeof (DateTimeSources), "Minutes")]
		public void Next_With_Minute_Range(int minutes)
		{
			// Arrange
			var min = new DateTime(1970, 1, 1);
			var max = min.AddMinutes(minutes);

			var randomDateTime = new RandomDateTime(min, max);

			// Act
			var random = randomDateTime.Next();

			// Assert
			Assert.GreaterOrEqual(random, min);
			Assert.LessOrEqual(random, max);
		}

		[Test, TestCaseSource(typeof (DateTimeSources), "Seconds")]
		public void Next_With_Second_Range(int seconds)
		{
			// Arrange
			var min = new DateTime(1970, 1, 1);
			var max = min.AddSeconds(seconds);

			var randomDateTime = new RandomDateTime(min, max);

			// Act
			var random = randomDateTime.Next();

			// Assert
			Assert.GreaterOrEqual(random, min);
			Assert.LessOrEqual(random, max);
		}
	}
}